debug:=yes#

target:=MediaParser
ffmpeg:=ffmpeg
ffmpeg_tag:=.ffmpeg
ffmpeg_libs:= -lavformat -lavcodec -lavutil

third-party-dir:=third-party-lib
third-party-lib:=$(third-party-dir)/lib
third-party-inc:=$(third-party-dir)/include

CC := g++
CXXFLAGS += -I$(third-party-inc) -D__STDC_CONSTANT_MACROS
LDFLAGS += -L$(third-party-lib) $(ffmpeg_libs) -lm -lpthread -lz -lva


target_list += $(target)
ifeq (yes, $(debug))
	CXXFLAGS += -g
	CFLAGS += -g
else
	target_list += strip 
endif

objs := main.o  \
        mediaparser.o

deps := $(objs:.o=.d) 

all: third-party dep  $(target_list) 

$(target): $(objs)
	$(CC)  -o $@ $^  $(LDFLAGS)

strip:
	strip $(target)

third-party: $(ffmpeg)

$(ffmpeg): $(ffmpeg_tag)
$(ffmpeg_tag):	
	(cd $(ffmpeg) && ./configure --prefix=../$(third-party-dir)/&&make -j4 && make install&& touch ../$(ffmpeg_tag))

dep: $(deps)

%.d:%.cc
	@set -e; rm -rf $@; \
	$(CC) -MM $(CXXFLAGS) $< > $@.$$$$; \
	sed 's,\($*\)\.o[:]*,\1.o $@:,g' < $@.$$$$ > $@;\
	rm -rf $@.$$$$

.PHONY:clean clean-dist strip dep

clean:
	rm -f *.o *.a *.d *.d.* 
	rm -rf $(target)

distclean: clean
	-(cd $(ffmpeg) && make distclean)
	rm -f $(ffmpeg_tag)
	rm -rf $(third-party-dir)


-include $(deps)
